package com.aaa.controller.scl;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.mht.MhtQuestion;
import com.aaa.entity.scl.TsclQuestion;
import com.aaa.service.scl.TsclQuestionService;
import com.aaa.util.EasyExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("tscl")
public class TsclQuestionController {
    @Resource
    private TsclQuestionService tsclService;


    /**
     * 查询题目信息
     */
    @ResponseBody
    @RequestMapping("findAllSCL")
    public LayData findAllSCL(MyPage myPage,TsclQuestion tsclQuestion){
        PageInfo all = tsclService.selectAll(myPage,tsclQuestion);
        LayData layData = new LayData(all);
        return layData;

    }

    /**
     * 导入excel表的数据
     */
    @PostMapping("addAll")
    @ResponseBody
    public LayData sclUploadExcel(MultipartFile file) throws IOException {
        List<Object> list = EasyExcelUtil.readExcel(file, new TsclQuestion(), 1,1);
        Boolean isNO = tsclService.inductsExcelFile(list);
        return new LayData(isNO);
    }



    /**
     * 添加题目
     */
    @PostMapping("addSCL")
    @ResponseBody
    public LayData addSCL(TsclQuestion tscl){
        return new LayData(tsclService.addSCL(tscl));
    }
    /**
     * 删除题目
     */
    @PostMapping("delSCL")
    @ResponseBody
    public LayData delSCL(TsclQuestion tscl){
        Boolean isNO = tsclService.delSCL(tscl);
        return new LayData(isNO);

    }

    /**
     *   查询题目序号是否已经使用
     */
    @PostMapping("/checkQId{qid}")
    @ResponseBody
    public LayData checkQId(@PathVariable Integer qid){
        Boolean isNo = tsclService.checkQId(qid);
        return new LayData(isNo);
    }

}
